/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.jul.giftmanager.ui;

import com.alee.laf.button.WebButton;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author user
 */
public class ButtonsPanel extends JPanel
{
    private WebButton okBtn;
    private WebButton applyBtn;
    private WebButton cancelBtn;

    public ButtonsPanel(ButtonsPanelState... buttonsPanelState)
    //varargs (объявление массива (...) или ([]). Только в случае ... массив не обязательно инициализировать)
    //но такое объявление должно идти всегда последним аргументом
    {
        okBtn = new WebButton();
        applyBtn = new WebButton();
        cancelBtn = new WebButton();
        init(buttonsPanelState);
    }
    
    private void init(ButtonsPanelState... buttonsPanelState){
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        add(Box.createHorizontalGlue());
             
        for (int i = 0; i < buttonsPanelState.length; i++)
        {
            switch(buttonsPanelState[i]){
                case APPLY_BTN:
                    add(applyBtn);
                    add(Box.createHorizontalStrut(5));
                    break;
                    case OK_BTN:
                    add(okBtn);
                    add(Box.createHorizontalStrut(5));
                    break;
                    case CANCEL_BTN:
                    add(cancelBtn);
                    add(Box.createHorizontalStrut(5));
                    break;
            } 
        }
        add(Box.createHorizontalGlue());
    }
    
    public void setOkBtnAction(Action okAction){
        okBtn.setAction(okAction);
    }
    
    public void setApplyBtnAction(Action applyAction){
        applyBtn.setAction(applyAction);
    }
    
    public void setCancelBtnAction(Action cancelAction){
        cancelBtn.setAction(cancelAction);
    }
    
    public static enum ButtonsPanelState{
        OK_BTN, APPLY_BTN, CANCEL_BTN
    }
    
    
    public static void main(String[] args)
    {
        JFrame frame = new JFrame();
        ButtonsPanel buttonsPanel = new ButtonsPanel(ButtonsPanelState.APPLY_BTN, ButtonsPanelState.CANCEL_BTN, ButtonsPanelState.OK_BTN);
        buttonsPanel.setOkBtnAction(new AbstractAction("Ok")
        {    
            @Override
            public void actionPerformed(ActionEvent ae)
            {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        
        buttonsPanel.setApplyBtnAction(new AbstractAction("Apply")
        {
            @Override
            public void actionPerformed(ActionEvent ae)
            {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        
        buttonsPanel.setCancelBtnAction(new AbstractAction("Cancel")
        { 
            @Override
            public void actionPerformed(ActionEvent ae)
            {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        
        frame.getContentPane().add(buttonsPanel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
